package com.mozz.finally_work.dao;

import com.mozz.finally_work.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface CategoryDao {

    /*通过用户id获取所有的分类*/
    @Select("SELECT category.*, count(*) as count  FROM category join user on user.id=category.user_id  join blog_category on blog_category.category_id=category.id  where user.id=#{userId} group by category.category_name")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "count", property = "count"),
    })
    List<Category> queryALlCategoryByUserIdWithCount(String userId);

    /*通过用户id获取所有的分类*/
    @Select("SELECT category.*  FROM category join user on user.id=category.user_id where user.id=#{userId} group by category.id")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "count", property = "count"),
    })
    List<Category> queryALlCategoryByUserId(String userId);

    /*添加分类*/
    @Insert("INSERT INTO category(id, user_id, category_name) values(#{id},#{userId},#{categoryName})")
    Integer addCategory(@Param("id") String id, @Param("userId") String userId, @Param("categoryName") String categoryName);
}
